/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package push2java;

/**
 *
 * @author Admin
 */
public class BooleanInstructions {

    public static void AND(State state) {
        if (state.booleanStack.size() >= 2) {
            Boolean arg1 = (Boolean) state.booleanStack.pop();
            Boolean arg2 = (Boolean) state.booleanStack.pop();
            state.booleanStack.push(arg1 && arg2);
        }
    }

    public static void OR(State state) {
        if (state.booleanStack.size() >= 2) {
            Boolean arg1 = (Boolean) state.booleanStack.pop();
            Boolean arg2 = (Boolean) state.booleanStack.pop();
            state.booleanStack.push(arg1 || arg2);
        }
    }

    public static void NOT(State state) {
        if (state.booleanStack.size() >= 1) {
            Boolean arg1 = (Boolean) state.booleanStack.pop();
            state.booleanStack.push(!arg1);
        }
    }

    public static void NAND(State state) {
        if (state.booleanStack.size() >= 2) {
            Boolean arg1 = (Boolean) state.booleanStack.pop();
            Boolean arg2 = (Boolean) state.booleanStack.pop();
            state.booleanStack.push(!(arg1 && arg2));
        }
    }

    public static void NOR(State state) {
        if (state.booleanStack.size() >= 2) {
            Boolean arg1 = (Boolean) state.booleanStack.pop();
            Boolean arg2 = (Boolean) state.booleanStack.pop();
            state.booleanStack.push(!(arg1 || arg2));
        }
    }
}
